package org.itboys.core.controller.front;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.itboys.commons.CommonConstants;
import org.itboys.core.service.mongo.front.SundayFrontVillageService;
import org.itboys.core.util.ResponseMessage;
import org.itboys.framework.spring.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author：贾琦磊
 * @Date：2018/8/8
 * @Description：小区
 */
@Controller
@Api(value = "village",description = "小区")
@RequestMapping("sunday/mobile/village")
public class SundayFrontVillageController extends BaseController{
    @Autowired
    private SundayFrontVillageService villageService;

    @RequestMapping("/select")
    @ApiOperation("分页获取小区")
    public void select(HttpServletRequest request, HttpServletResponse response
    ,@ApiParam(value = "省id") @RequestParam(value = "provinceId",required = false)Long provinceId
            ,@ApiParam(value = "市id")@RequestParam(value = "cityId",required = false) Long cityId
            ,@ApiParam(value = "区id")@RequestParam(value = "districtId",required = false)Long districtId
            ,@ApiParam(value = "小区名")@RequestParam(value = "name",required = false)String name
            ,@ApiParam(required = true,value = "分页参数,第几页") @RequestParam(value = "pageSize", required = true) String pageSize
            ,@ApiParam(required = true,value = "分页参数，每页大小") @RequestParam(value = "pageNumber", required = true) String pageNumber){
        try{

            ResponseMessage.success(villageService.select(request));
        }catch (Exception e){
            String msg = CommonConstants.ERROMSG;
            Integer code=CommonConstants.FAIL_CODE;
            //自定义异常（签名错误）
            if(e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")){
                msg=e.getMessage();
                //token已过期
            }else if(e.getClass().getSimpleName().equalsIgnoreCase("TokenException")){
                code=CommonConstants.TOKEN_CODE;
                msg=CommonConstants.TOKENMSG;
            }else{
                logger.error("/sunday/mobile/village/select----e="+e.getMessage());
            }
            e.printStackTrace();
            ResponseMessage.error(code,msg);
        }
    }
}
